<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
require_once("../conn.php");
if (isset($_POST['id'])) {
    $id = checkTrim($_POST['id']);
}
$code = checkTrim($_POST['code']);
$name = checkTrim($_POST['name']);
$url = checkTrim($_POST['url']);
$version = $_POST['version'];
$description = $_POST['description'];
$isModify = $_POST['isModify'];
$price = checkTrim($_POST['original']);

if (isset($_POST['price'])) {
    $goodprice = checkTrim($_POST['price']);
} else {
    $goodprice = $price;
}
if ($goodprice == "") {
    $goodprice = $price;
}
if (isset($_POST['promotion'])) {
    $promotion = checkTrim($_POST['promotion']);
} else {
    $promotion = 0;
}
echo $promotion."xxx";
$db = new DBC();
if ($isModify == 1) {
    $sql = "UPDATE t_hibaby_scenario SET code = '" . $code . "',name = '" . $name . "',url = '" . $url . "',original = " . $price . ",price = " . $goodprice . ",promotion = " . $promotion . ",version = '" . $version . "',description = '" . $description . "' WHERE id = " . $id;
} else {
    $sql = "INSERT INTO t_hibaby_scenario(code,name,version,url,original,price,promotion,description,createTime) VALUES('" . $code . "','" . $name . "','" . $version . "','" . $url
            . "'," . $price . "," . $goodprice . "," . $promotion . ",'" . $description . "',now())";
}
echo $sql;
$transfer = "scenarioList.php?menu=scenario";
if ($db->execute($sql)) {
    //success
    //    echo "<script language='javascript'>alert('成功'); </ script>";
    echo "<script language='javascript'>location='" . $transfer . "';</script>";
} else {
    //failue
    echo "<script language='javascript'>alert('失败'); </script>";
   // echo "<script language='javascript'>history.back();</script>";
}

function checkTrim($item) {
    if (isset($item)) {
        $item = trim($item);
    } else {
        $item = "";
    }
    return $item;
}
?>
